<template>
  <div class="box">
    <div class="title">
      <div @click="eleme" class="eleme">ele.me</div>
      <!-- <van-icon class="icon1" name="arrow-left" /> -->
      <span class="icon2" @click="register">登录|注册</span>
    </div>
    <div class="location">
      <div class="current">
        <div class="left1">当前定位城市:</div>
        <div class="cengt"></div>
        <div class="right1"><p>定位不准时时,请在城市列表中选择</p></div>
      </div>

      <div class="toponym" @click="$router.push('/city')">
        <div class="left" @click="skipFn(location.id)">{{ location.name }}</div>
        <div class="right"><van-icon name="arrow" /></div>
      </div>
    </div>

    <div class="hot addhot">
      <div class="hots">热门城市</div>
      <ul class="content">
        <li @click="skipFn(data.id)" v-for="data in arr" :key="data.id">
          {{ data.name }}
        </li>
      </ul>
    </div>
    <!-- 第一层 -->
    <div class="hot addhot" v-for="(item, index) in list" :key="index">
      <div class="num">
        <div class="hots">{{ index }} &nbsp;(按字母排序)</div>
      </div>
      <!-- 第二层 -->
      <ul class="content" v-for="arr in item" :key="arr.id">
        <li @click="skipFn(arr.id)" class="lis">{{ arr.name }}</li>
      </ul>
    </div>
  </div>
</template>

<script>
import { cityOrientation } from "../api/index";
export default {
  data() {
    return {
      list: [], //全部城市
      arr: [], //热门城市
      location: "",
      group: "group", //热门城市
      hot: "hot",
      guess: "guess",
      num: [],
    };
  },

  created() {
    cityOrientation({ type: this.hot }).then((res) => {
      console.log("53", res.data);
      this.arr = res.data;
    });
    cityOrientation({ type: this.group }).then((res) => {
      console.log(res);

      let lis = res.data;
      function objkeySort(lis) {
        let newkey = Object.keys(lis).sort();
        let newobj = {};
        for (let i = 0; i < newkey.length; i++) {
          newobj[newkey[i]] = lis[newkey[i]];
        }
        return newobj;
      }
      objkeySort(lis);
      let jsonstr = JSON.stringify(objkeySort(lis));
      this.list = JSON.parse(jsonstr);
      console.log("74", this.num);
    });
    cityOrientation({ type: this.guess }).then((res) => {
      console.log("63", res.data.id);
      this.location = res.data;
    });
  },

  methods: {
    //刷新
    eleme() {
      location.reload();
    },
    //登录注册路径
    register() {
      //   this.$router.push({
      //     //   登录注册
      //     '/login'});
      this.$router.push("/login");
    },
    skipFn(id) {
      this.$router.push({
        path: "/city",
        query: {
          id,
        },
      });
      console.log("80", id);
      localStorage.setItem("userid", id);
    },
  },
};
</script>

<style lang="less" scoped>
.location {
  width: 100%;
  height: 140px;

  margin-top: 80px;
  .current {
    height: 84.9975px;
    background-color: #fff;
    display: flex;
    .left1 {
      width: 200px;
      font-size: 24.9975px;
      line-height: 80.0025px;
      padding:0 15px;
     
      flex: 1;
    }
    .right1 {
      width: 130px;
      position: relative;
      font-weight: 700;
      font-size: 20.0025px;
      line-height: 80.0025px;
      padding-left: 200px;
     
      color: #9f9f9f;
      p {
        position: absolute;
        right: 20px;
      }
    }
  }
  .toponym {
    border-top: 1px solid #9f9f9f;
    background-color: #fff;
    height: 85px;
    display: flex;
    .left {
      flex: 1;
      margin-left: 20px;
      font-size: 25px;
      line-height: 80px;
    }
    .right {
      text-align: center;
      flex: 1;
      .van-icon {
        margin-left: 350px;
        line-height: 80px;
        font-size: 25px;
      }
    }
  }
}

/deep/.hot {
  overflow: hidden;
  width: 100%;
  // height: 200px;
  margin-top: 40px;
  color: #666666;
  background-color: #fff;
  .hots {
    width: 100%;
    height: 60px;
    color: #666666;
    line-height: 60px;
    font-size: 20px;
    margin-left: 15px;
  }
  .content {
    width: 100%;
    li {
      float: left;
      width: 24.6%;
      border: 1px solid #e4e4e4;
      height: 70px;
      background-color: #fff;
      color: #3190e8;
      text-align: center;
      line-height: 70px;
      font-size: 25px;
      // color:#3190e8 ;
    }
    .lis {
      color: #666666;
    }
  }
}
.box {
  background-color: #ebebeb;
}

.title {
  position: fixed;
  top: 0;
  margin-bottom: 0px;
  width: 100%;
  height: 80px;
  background-color: #3190e8;
  .icon1 {
    position: absolute;
    left: 20px;
    line-height: 80px;
    color: #fff;
    font-size: 25px;
  }
  .eleme {
    font-size: 35px;
    margin-left: 15px;
    line-height: 80px;
    color: #fff;
  }
  .icon2 {
    margin-top: -76px;
    position: absolute;
    right: 20px;
    line-height: 80px;
    color: #fff;
    font-size: 25px;
  }
}
</style>